package utils

import "math"

const (
	intSize = 32 << (^uint(0) >> 63)
	MaxInt  = 1<<(intSize-1) - 1
	MinInt  = -1 << (intSize - 1)
)

func Abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

func GetMax(nums ...int) int {
	var max = nums[0]
	for i := 1; i < len(nums); i++ {
		if max < nums[i] {
			max = nums[i]
		}
	}
	return max
}

func GetMin(nums ...int) int {
	var min = nums[0]
	for i := 1; i < len(nums); i++ {
		if min > nums[i] {
			min = nums[i]
		}
	}
	return min
}

func IsPrime(num int) bool {
	if num <= 3 {
		return num > 1
	}
	if num%6 != 1 && num%6 != 5 {
		return false
	}
	var sqrt = int(math.Sqrt(float64(num)))
	for i := 5; i < sqrt; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}
	return true
}

func CountBit(num int) int {
	var cnt int
	for num > 0 {
		num &= num - 1
		cnt++
	}
	return cnt
}
